import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
const statusData = [
	{ name:'停用', 		value: '0' },
	{ name:'待校准', 	value: '1' },
	{ name:'通过', 		value: '2' },
]
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		// 搜索表单列表
		forms : [
			{ label: '项目名称',		name: 'kind_id',	type: 'select', loading:true, width:250 },
			{ label: '状态',			name: 'status',			half:true, type: 'select', required:true, data: statusData },
		],
	}
	query = {}
	model = {}
	
	componentDidMount(){
		const { uuid } = $fn.query()
		if(uuid){ 
			this.query = { kind_id: uuid }
			this.uuid = uuid
		}
		//
		if(window.isInit){
			this.fetch()
		}
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		$cache.then( async f => {
			$fn.setRows([ forms ], 'kind_id', await f.getCache({api:'all_project_select'}) )
			// 设置默认值
			if(this.uuid){ 
				this.searchFormRef.setValue({ kind_id: this.uuid })
				this.fetch(this.uuid)
			}
			
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = (uuid = '') => $fn.fetch.call(this,'kd-check-plan/checkLog', {kind_id: uuid})
	
	// 表单
	cols = [
		{ title: '项目名称',			dataIndex: 'kind_name' },
		{ title: '结果', 			dataIndex: 'remark', 		width:200 },
		{ title: '校准人', 			dataIndex: 'oprate_name', 		width:200 },
		{ title: '状态', 			dataIndex: 'status_name', 		width:200,},
		{ title: '实际校准时间', 		dataIndex: 'created_at', 	width:200, align:'center' },
	]
	// 操作按钮
	controls = () => [
		this.uuid && Controls.back.call(this)
	]
	
	render(){
		return (
			<Page title='校准记录' controls={this.controls()}>
				{/* 搜索 */}
				{ SearchForm.call(this, { onForm: this.getSelect  } ) }
				{/* 表格 */}
				{ Table.call(this,{isInit:window.isInit}) }
			</Page>
		)
	}
}

export default Index